package com.zls.service.impl;

import com.zls.mapper.TaskplanMapper;
import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.pojo.Taskplan;
import com.zls.service.TaskplanService;
import com.zls.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class TaskplanServiceImpl implements TaskplanService {
    @Autowired
    private TaskplanMapper taskplanMapper;

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        String queryString = queryPageBean.getQueryString();//查询条件
        //total总记录数
        List<Taskplan> page = taskplanMapper.findTask((currentPage - 1) * pageSize, pageSize,queryString);
        //rows  当前页的数据
        Long count = taskplanMapper.count(queryString);
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public List<Taskplan> findAll() {
        return taskplanMapper.findAll();
    }

    @Override
    @Transactional
    public int addTaskplan(Taskplan taskplan) {
        taskplan.setUpdatetime(new Date());
        taskplan.setTid(UUIDUtils.uuid());
        int i = taskplanMapper.addTaskplan(taskplan);
        return i;
    }

    @Override
    public Taskplan findByTid(String tid) {
        return taskplanMapper.findByTid(tid);
    }

    @Override
    @Transactional
    public int editTaskplan(Taskplan taskplan) {
        taskplan.setUpdatetime(new Date());
        int i = taskplanMapper.updateTaskplan(taskplan);
        return i;
    }

    @Override
    @Transactional
    public int deleteTaskplan(String tid) {
        int i = taskplanMapper.deleteTaskplan(tid);
        return i;
    }

    @Override
    public List<Taskplan> findByBid(String bid) {
        return taskplanMapper.findByBid(bid);
    }
}
